type
  TinfoID = TinlID;
  TinfoTitle = TinlStringType;
  TinfoVersn = TinlModifctn;
  TdataID = TinlID;
  TdataName = TinlNameType;
  TdataTime = TinlTimeStamp;
  TdataVersion = TinlModifctn;
  TdataHash = TinlHash;

  { TdataInfo }

  TdataInfo = class
    constructor Create(idProto: TinfoID; DB: pointer);
    constructor Create(Proto: TdataInfo; const AName: TdataName);
    destructor Destroy; override;
  private
    diID        : TinfoID;
    diTitle     : TinfoTitle;
    diPrtotype  : TdataInfo;
    diPrtpID    : TinfoID;
    diMdfctn    : TinfoVersn;
    diName      : TdataName;
    diHash      : TdataHash;
    diMdfTime   : TdataTime;

    procedure EditTitle(const newTitle: TinfoTitle);
  public
    property Name: TdataName read diName;
    property Hash: TdataHash read diHash;
    property Title: TinfoTitle read diTitle write EditTitle;
    property ver: TinfoVersn read diMdfctn;
  end;

  TdataType = (dtaAny, dtaSys, dtaModule, dtaProc, dtaFunc, dtaVar, dtaTemplate, dtaSection, dtaAttr, dtaUnit);
  TLinkType = (lnkChild, lnkAttr, lnkCnctn);

  TinlGoal = class

  end;

  TinlGoalsList = class

  end;

  TinlTask = class

  end;

  TinlTasksList = class

  end;

  TinlSolution = class

  end;

  TinlLibProcInfo = class

  end;

  TSoltnSearchData = record
    Name: TinlNameType;
  end;

  diSource = (dsInput, dsCalc, dsLab);

  { TIIntgrlProject }

  TIIntgrlProject = class
    Goals: TinlGoalsList;
    Tasks: TinlTasksList;
    Objects: TList;
    Solutions: TList;
    Variants: TList;
    Datas: TList;
    constructor Create;
    destructor Destroy; override;
//    function FindProcByName(proc: TinlNameType): TinlLibProcInfo;
//    function FirstSoltnByOut(var SSD: TSoltnSearchData): TinlSolution;
//    function NextProcsByOut(var Outs: array of TIntgrlValueInfo; var SSD: TSoltnSearchData): TinlSolution;
  end;

  ==========================================================================================================

  { TIIntgrlProject }

constructor TIIntgrlProject.Create;
begin

end;

destructor TIIntgrlProject.Destroy;
begin

  inherited Destroy;
end;

{function TIIntgrlProject.FindProcByName(proc: TinlNameType): TinlLibProcInfo;
begin

end;

function TIIntgrlProject.FirstSoltnByOut(var SSD: TSoltnSearchData
  ): TinlSolution;
begin

end;

function TIIntgrlProject.NextProcsByOut(var Outs: array of TIntgrlValueInfo;
  var SSD: TSoltnSearchData): TinlSolution;
begin

end;
}
{ TdataInfo }

constructor TdataInfo.Create(idProto: TinfoID; DB: pointer);
begin
  inherited Create;
  diPrtpID := idProto;

end;

constructor TdataInfo.Create(Proto: TdataInfo; const AName: TdataName);
begin
  inherited Create;
  diPrtotype := Proto;
  diName := AName;
  if assigned(Proto) then diPrtpID := Proto.diID else diPrtpID := noID;
  diMdfTime := NowItIs;
  diMdfctn := 1;
end;

destructor TdataInfo.Destroy;
begin

  inherited Destroy;
end;

procedure TdataInfo.EditTitle(const newTitle: TinfoTitle);
begin
  diTitle := newTitle;
end;

=========================================================================================
  TIntgrlElmntClass = (icElmnt, icLink, icGrp);
TIntgrlDataTypes = (dtNone, dtQuality, dtObject, dtLink, dtValue, dtData, dtMethod );

{ TIntgrlDataInfo }

TIntgrlDataInfo = class
  constructor Create(from: TIntgrlActor; tothe: TIntgrlActor);
  constructor Create(user: TIntgrlActor);
  constructor Create;
  destructor Destroy; override;
private
  diID: TinlID;
  diType: TIntgrlDataTypes;
  diNeed: TIntgrlDataNeed;
  diTrust: TIntgrlDataTrust;
  diProducer: TIntgrlActor;
  diRecipient: TIntgrlActor;
  diPrtotype: TIntgrlDataInfo;
  diPrtpID: TinlID;
  diHash: TinlHash;
  diMdfTime: TinlTimeStamp;
  {$ifdef iiVersions}
  diMdfctn: TinlModifctn;
  {$endif}
  diInfo: TinlRubricType;
protected
  function BeginString: TinlStringType; virtual;
  function EndString: TinlStringType; virtual;
  function FromToString: TinlStringType; virtual;
  function TimeString: TinlStringType; virtual;
  {$ifdef iiVersions}
  function VerString: TinlStringType; virtual;
  {$endif}
public
  property pr: TIntgrlActor read diProducer;
  property rc: TIntgrlActor read diRecipient;
  property pt: TIntgrlDataInfo read diPrtotype;
  property nd: TIntgrlDataNeed read diNeed;
  property df: TIntgrlDataTrust read diTrust;
  property hsh: TinlHash read diHash;
  property ch: TinlTimeStamp read diMdfTime;
  {$ifdef iiVersions}
  property v: TinlModifctn read diMdfctn;
  {$endif}
  property t: TIntgrlDataTypes read diType;
  function CreateCopy: TIntgrlDataInfo; virtual;
  function WriteToString: TinlStringType; virtual;
  procedure ReadFromString(str: TinlStringType); virtual;
end;

TIntgrlNameSpace = class;

{ TIntgrlNameObject }

TIntgrlNameObject = class(TIntgrlDataInfo)
  constructor Create(aName: TinlNameType);
  constructor Create(aName: TinlNameType; aOwner: TIntgrlNameSpace);
  destructor Destroy; override;
private
  nmName: TinlNameType;
  nmOwner: TIntgrlNameSpace;
  nmLongName: TinlNameType;
  nmTitle: TinlLongNameType;
  nmBrief: TinlRubricType;
protected
  function GetFullPath: TinlNameType; virtual;
  function BeginString: TinlStringType; override;
  function EndString: TinlStringType; override;
public
  property iiName: TinlNameType read nmName;
  property iiFullPath: TinlNameType read GetFullPath;
  property iiTitle: TinlLongNameType read nmTitle;
  function WriteToString: TinlStringType; override;
  procedure ReadFromString(str: TinlStringType); override;
end;

{ TIntgrlNameSpace }

TIntgrlNameSpace = class(TIntgrlNameObject)
private
  nmItems: array of TIntgrlNameObject;
protected
  function GetFullPath: TinlNameType; override;
  function BeginString: TinlStringType; override;
  function EndString: TinlStringType; override;
public
  constructor Create;
  destructor Destroy; override;
  function FindUp(aName: TinlNameType): TIntgrlNameObject;
  function FindDown(aName: TinlNameType): TIntgrlNameObject;
  function FindLocal(aName: TinlNameType): TIntgrlNameObject;
  function FindLocalAndUp(aName: TinlNameType): TIntgrlNameObject;
  function FindLocalAndDown(aName: TinlNameType): TIntgrlNameObject;
  function IsDownPathExist(aName: TinlNameType): TinlLogicType;
  function CreateItem(aName: TinlNameType): TIntgrlNameObject;
  procedure InsertItem(newItem: TIntgrlNameObject);
  procedure RemoveItem(oldItem: TIntgrlNameObject);
  function WriteToString: TinlStringType; override;
  procedure ReadFromString(str: TinlStringType); override;
end;

{ TIntgrlQuality }

TIntgrlQuality = class(TIntgrlNameObject)
protected
  function BeginString: TinlStringType; override;
  function EndString: TinlStringType; override;
public
  constructor Create;
  destructor Destroy; override;
  function WriteToString: TinlStringType; override;
  procedure ReadFromString(str: TinlStringType); override;
end;

TIntgrlValueInfo = class
  viPrototype: pointer;
  viTrust: TIntgrlDataTrust;

end;

{ TIntgrlValueObject }

TIntgrlValueObject = class(TIntgrlDataInfo)
  diValueInfo: TIntgrlValueInfo;
  diValue: pointer;

end;

{ TIntgrlProprty }

TIntgrlProprty = class(TIntgrlNameObject)
  prValue: TIntgrlValueObject;
  constructor Create;
  destructor Destroy; override;
end;

{ TIntgrlObject }

TIntgrlObject = class(TIntgrlNameSpace)
  obPrttype: TIntgrlObject;
  obPrttName: TinlNameType;
  obPrttExcls: array of TIntgrlNameObject;
  obProps: array of TIntgrlProprty;
  constructor Create;
  destructor Destroy; override;
end;

TsrcTxtID = integer;
TsrcTxtPstn = integer;

TGeneralInfo = class
  srcTxtID: TsrcTxtID;
  StartPstn: TsrcTxtPstn;
  EndPstn: TsrcTxtPstn;

end;

TinfSource = (isInput, isEdit, isInherit, isNeed, isRecmnd);
TinfValdtn = (icProvd, icAccptd, icRejctd, icRevisd, icMissd);

{ TIntgrlQuality }

function TIntgrlQuality.BeginString: TinlStringType;
begin
  Result := inherited BeginString;
end;

function TIntgrlQuality.EndString: TinlStringType;
begin
  Result := inherited EndString;
end;

constructor TIntgrlQuality.Create;
begin

end;

destructor TIntgrlQuality.Destroy;
begin
  inherited Destroy;
end;

function TIntgrlQuality.WriteToString: TinlStringType;
begin
  Result := inherited WriteToString;
end;

procedure TIntgrlQuality.ReadFromString(str: TinlStringType);
begin
  inherited ReadFromString(str);
end;

{ TIntgrlDataInfo }

constructor TIntgrlDataInfo.Create;
begin
  diMdfTime := NowItIs;
  diMdfctn := 0;

end;

function TIntgrlDataInfo.BeginString: TinlStringType;
begin
  result := '<DI>';
end;

function TIntgrlDataInfo.EndString: TinlStringType;
begin
  result := '</DI>';
end;

function TIntgrlDataInfo.FromToString: TinlStringType;
begin
  result := '<@'+diProducer.GetName+'~'+diRecipient.GetName+'>';
end;

function TIntgrlDataInfo.TimeString: TinlStringType;
begin
  result := '<T'+'00:00:00'+'>';
end;

function TIntgrlDataInfo.VerString: TinlStringType;
begin
  result := '<V'+'0'+'>';
end;

constructor TIntgrlDataInfo.Create(from: TIntgrlActor; tothe: TIntgrlActor);
begin
  Create;

end;

constructor TIntgrlDataInfo.Create(user: TIntgrlActor);
begin
  Create;

end;

destructor TIntgrlDataInfo.Destroy;
begin

  inherited Destroy;
end;

function TIntgrlDataInfo.CreateCopy: TIntgrlDataInfo;
begin

end;

function TIntgrlDataInfo.WriteToString: TinlStringType;
begin
  result := BeginString+FromToString+VerString+TimeString+EndString;
end;

procedure TIntgrlDataInfo.ReadFromString(str: TinlStringType);
begin

end;

{ TIntgrlNameObject }

function TIntgrlNameObject.GetFullPath: TinlNameType;
begin
  result := nmOwner.GetFullPath + nmName;
end;

function TIntgrlNameObject.BeginString: TinlStringType;
begin
  Result := inherited BeginString;
end;

function TIntgrlNameObject.EndString: TinlStringType;
begin
  Result := inherited EndString;
end;

constructor TIntgrlNameObject.Create(aName: TinlNameType);
begin

end;

constructor TIntgrlNameObject.Create(aName: TinlNameType; aOwner: TIntgrlNameSpace);
begin

end;

destructor TIntgrlNameObject.Destroy;
begin

  inherited Destroy;
end;

function TIntgrlNameObject.WriteToString: TinlStringType;
begin
  Result := inherited WriteToString;
end;

procedure TIntgrlNameObject.ReadFromString(str: TinlStringType);
begin
  inherited ReadFromString(str);
end;

{ TIntgrlNameSpace }

function TIntgrlNameSpace.GetFullPath: TinlNameType;
begin
  Result := inherited GetFullPath;
end;

function TIntgrlNameSpace.BeginString: TinlStringType;
begin
  Result := inherited BeginString;
end;

function TIntgrlNameSpace.EndString: TinlStringType;
begin
  Result := inherited EndString;
end;

constructor TIntgrlNameSpace.Create;
begin
//  inherited Create;

end;

destructor TIntgrlNameSpace.Destroy;
begin

  inherited Destroy;
end;

function TIntgrlNameSpace.FindUp(aName: TinlNameType): TIntgrlNameObject;
begin

end;

function TIntgrlNameSpace.FindLocal(aName: TinlNameType): TIntgrlNameObject;
var
  i: TinlID;
begin
  for i := Low(nmItems) to High(nmItems) do
    if (nmItems[i].nmName=aName) then Result := nmItems[i];
end;

function TIntgrlNameSpace.FindDown(aName: TinlNameType): TIntgrlNameObject;
begin

end;

function TIntgrlNameSpace.FindLocalAndUp(aName: TinlNameType): TIntgrlNameObject;
begin

end;

function TIntgrlNameSpace.FindLocalAndDown(aName: TinlNameType): TIntgrlNameObject;
begin

end;

function TIntgrlNameSpace.IsDownPathExist(aName: TinlNameType): boolean;
begin

end;

function TIntgrlNameSpace.CreateItem(aName: TinlNameType): TIntgrlNameObject;
begin

end;

procedure TIntgrlNameSpace.InsertItem(newItem: TIntgrlNameObject);
begin

end;

procedure TIntgrlNameSpace.RemoveItem(oldItem: TIntgrlNameObject);
begin

end;

function TIntgrlNameSpace.WriteToString: TinlStringType;
begin
  Result := inherited WriteToString;
end;

procedure TIntgrlNameSpace.ReadFromString(str: TinlStringType);
begin
  inherited ReadFromString(str);
end;

{ TIntgrlProprty }

constructor TIntgrlProprty.Create;
begin

end;

destructor TIntgrlProprty.Destroy;
begin
  inherited Destroy;
end;

{ TIntgrlObject }

constructor TIntgrlObject.Create;
begin

end;

destructor TIntgrlObject.Destroy;
begin
  inherited Destroy;
end;



  TIntgrlTypedValue = class
    voType: TIntgrlTypeInfo;
    voValueInfo: TIntgrlValueInfo;
    constructor Create;
    destructor Destroy; override;
    procedure Load;
    procedure Save;

  end;

{ TIIntegralPlugin }

TIIntegralPlugin = class
  constructor Create(wCfg: TIntgrlCfgrtn; aName: TinlNameType);
  destructor Destroy; override;
private
  { private declarations }
  FStatus: TPluginState;
  FName: TinlNameType;    // Имя модуля
  FTitle: TinlStringType; // Надпись в заголовоках
  FCfgn: TIntgrlCfgrtn;   // Ссылка на конфигурацию, в составе которой этот плагин
  FParams: TStrings;
  function GetParamCount: integer;
  function GetParamName(Index: integer): TinlNameType;
  function GetParamValue(const Name: TinlNameType): TinlStringType;
  procedure SetParamValue(const Name: TinlNameType; const Value: TinlStringType);
protected
  procedure postInfo(s: TinlStringType); virtual;
  procedure postWarng(s: TinlStringType); virtual;
  procedure postError(s: TinlStringType); virtual;
  procedure Post(s: TinlStringType);
  procedure Warng(s: TinlStringType);
  procedure Error(s: TinlStringType);
  function GetPluginVersion: TinlModifctn; virtual; abstract;
  procedure GetParams(Params: TStrings); virtual; abstract;   //Заполнить список параметров по умолчанию
  procedure DoUpdateParams; virtual; abstract;
  function DoReset: boolean; virtual; abstract;
public
  property plgStatus: TPluginState read FStatus;
  property plgName: TinlNameType read FName;
  property plgVer: TinlModifctn read GetPluginVersion;
  property plgTitle: TinlStringType read FTitle;
  property prmCount: integer read GetParamCount;
  property prmName[Index: integer]: TinlNameType read GetParamName;
  property prmValue[const Name: TinlNameType]: TinlStringType read GetParamValue write SetParamValue;
  procedure UpdateParams; // Установка состояния по параметрам
  procedure Reset;        // Сброс состояния в установленное по параметрам
end;

constructor TIIntegralPlugin.Create(wCfg: TIntgrlCfgrtn; aName: TinlNameType);
begin
  FStatus := sInit;
  FName := aName;
//  WriteRunLog(logBgnMod + FName);
  if assigned(wCfg) then FCfgn := wCfg else FCfgn := nil;
  FParams := TStrings.Create;
end;

destructor TIIntegralPlugin.Destroy;
begin
  FStatus := sKill;
  FreeAndNil(FParams);
  inherited Destroy;
end;

function TIIntegralPlugin.GetParamCount: integer;
begin
  result := FParams.Count;
end;

function TIIntegralPlugin.GetParamName(Index: integer): TinlNameType;
begin
  result := FParams.Names[Index+1];
end;

function TIIntegralPlugin.GetParamValue(const Name: TinlNameType
  ): TinlStringType;
begin
  result := FParams.Values[Name];
end;

procedure TIIntegralPlugin.SetParamValue(const Name: TinlNameType;
  const Value: TinlStringType);
begin
  FParams.Values[Name] := Value;
end;

procedure TIIntegralPlugin.postInfo(s: TinlStringType);
begin
//  WriteRunLog('Info.cfg ' + s);
end;

procedure TIIntegralPlugin.postWarng(s: TinlStringType);
begin
  WriteRunLog('Warning.cfg ' + s);
end;

procedure TIIntegralPlugin.postError(s: TinlStringType);
begin
  WriteRunLog('ERROR.cfg ' + s);
end;

procedure TIIntegralPlugin.Post(s: TinlStringType);
begin
  if assigned(FCfgn.pLOG) then
    FCfgn.pLOG.postInfo(FName + ': ' + s)
  else postInfo(FName + '> ' + s);
end;

procedure TIIntegralPlugin.Warng(s: TinlStringType);
begin
  if assigned(FCfgn.pLOG) then
    FCfgn.pLOG.postWarng(FName + ': ' + s)
  else postWarng(' --- ' + FName + '> ' + s);
end;

procedure TIIntegralPlugin.Error(s: TinlStringType);
begin
  if assigned(FCfgn.pLOG) then
    FCfgn.pLOG.postError(FName + ': ' + s)
  else postError(' *** ' + FName + '> ' + s);
end;

procedure TIIntegralPlugin.Reset;
begin
  Warng('Do Reset from status' + plgStatusNames[FStatus]);
  FStatus := sReset;
  if DoReset then FStatus := sGood else FStatus := sError;
end;

procedure TIIntegralPlugin.UpdateParams;
begin
  if FStatus = sInit then DoUpdateParams;
end;

{ TIIntegralModule }

TIIntegralModule = class(TIIntegralPlugin)
  constructor Create(wCfg: TIntgrlCfgrtn; modType: TModuleType);
  destructor Destroy; override;
private
  { private declarations }
  FType: TModuleType;
protected
  function GetPluginVersion: TinlModifctn; override;
  function DoReset: boolean; override;
public
  property mType: TModuleType read FType;
end;


function TIIntegralModule.GetPluginVersion: TinlModifctn;
begin
  Result := modVersInt[FType];
end;

function TIIntegralModule.DoReset: boolean;
begin
  Result := True;
end;

constructor TIIntegralModule.Create(wCfg: TIntgrlCfgrtn; modType: TModuleType);
begin
  FType := modType;
  inherited Create(wCfg, modNames[FType]);
  if assigned(wCfg) then wCfg.Set_Intgrl_module(Self);
  //----
end;

destructor TIIntegralModule.Destroy;
begin
  //----
  if assigned(FCfgn) then begin
    FCfgn := nil;
  end;
  WriteRunLog(logEndMod + FName);
  inherited Destroy;
end;

{ TDataMngrPlugin }

TDataMngrPlugin = class(TinlPlugin)
private
  FSrcName: TinlNameType;
  FSrcPath: TinlLongNameType;
  FConnected: boolean;
  FReaded: boolean;
protected
  property dbPath: TinlLongNameType read FSrcPath;
  property dbName: TinlNameType read FSrcName;
  procedure CreateDB; virtual; abstract;
  procedure ConnectDB; virtual; abstract;
  procedure CloseDB; virtual; abstract;
public
  property Connected: boolean read FConnected default false;
  constructor Create(wCfg: TIntgrlCfgrtn; const ASrc: TinlStringType);
  destructor Destroy; override;
end;

  TDataVersnPlugin = class(TIIntegralPlugin)

  end;

  TSVNDataVersn = class(TDataVersnPlugin)

  end;

  TCVSDataVersn = class(TDataVersnPlugin)

  end;

  TGitDataVersn = class(TDataVersnPlugin)

  end;

    // Таблицы справочной базы данных
      QuanttTblname = 'Velichin'; // Физические величины
      UnitTblname = 'EdIzmer';    // Единицы измерения
      SubstncTblname = 'Veschestv';  // Вещества и материалы
      AttrTblname = 'Svoystva';  // Свойства объектов

    // Поля таблицы величин
      QuanttIDFldName = 'qID';
      QuanttNameFldName = 'qNazvan';
      QuanttEngNameFldName = 'qName';
      QuanttUnitFldName = 'qEdIzm';

    // Поля таблицы единиц измерения
      UnitIDFldName = 'uID';
      UnitNotnFldName = 'uObozn';
      UnitNameFldName = 'uNazvan';
      UnitEngNameFldName = 'uName';
      UnitQuanFldName = 'uQuantt';
      UnitBasicFldName = 'uOsnovn';
      UnitConvFldName = 'uPreobr';

    // Поля таблицы параметров
      AttrIDFldName = 'aID';
      AttrNotnFldName = 'aObozn';
      AttrNameFldName = 'aNazvan';
      AttrQuanttFldName = 'aQuantt';
      AttrUnitFldName = 'aEdIzm';

    // Таблицы базы данных проекта
      ElmntTblname = 'Element';     // Компоненты

      ElmntIDFldName = 'elID';
      ElmntNameFldName = 'elName';
      ElmntOwnerFldName = 'elOwner';
      ElmntTypeFldName = 'elType';
      ElmntStateFldName = 'elState';
      ElmntSourceFldName = 'elSource';
      ElmntMdfctnFldName = 'elVersion';
      ElmntMdfTimeFldName = 'elTime';
      ElmntValueFldName = 'elValueString';

    maxQuanttNameSize = 32;
    maxUnitNotnSize = 8;
    maxUnitNameSize = 32;
    maxAttrNotnSize = 8;
    maxAttrNameSize = 32;

    idDebug = -4;
    idInfo = -11;
    idHint = -22;
    idWrng = -33;
    idError = -44;
    msgGRP: array [TMsgGrp] of TinlID = (idDebug, idInfo, idHint, idWrng, idError);

var
  LogActive: Boolean;

procedure StartRunLog;
begin
  writeln(StdOut, rlogHeader+b+pstVer+b+v2s(IIntgrlVer)+'(alpha) '+rlogCopyright+','+inlData);
  RunLog := nil;
  new(RunLog);
  try
    Assign(RunLog^, rlogFileName);
    if FileExistsUTF8(rlogFileName) then Append(RunLog^)
    else Rewrite(RunLog^);
  except
    Freemem(RunLog);
    RunLog := nil;
    writeln(StdOut, rlogErrorFile, b, rlogFileName);
  end;
  LogActive := RunLog <> nil;
  WriteRunLog(rlogStart +b+ DateTimeToStr(Now));
end;

procedure StopRunLog;
begin
  if LogActive then begin
    writeln(RunLog^, rlogFinish +b+ DateTimeToStr(Now));
    Close(RunLog^);
    Dispose(RunLog);
    LogActive := false;
  end;
  RunLog := nil;
  writeln(StdOut, rlogFooter);
end;

{Initialization
  StartRunLog;
Finalization
  StopRunLog;
end.}

{ TIntgrlTypeInfo }

function TIntgrlTypeInfo.GetValSize: integer;
begin
  result := tyValSize;
end;

constructor TIntgrlTypeInfo.Create;
begin
  //
end;

destructor TIntgrlTypeInfo.Destroy;
begin
  inherited Destroy;
end;

function TIntgrlTypeInfo.CreateEmptyVal: pointer;
begin
  result := nil;
end;

function TIntgrlTypeInfo.CreateValFromCopy(data: pointer): pointer;
begin
  result := AllocMem(tyValSize);
  Move(data^,result^,tyValSize);
end;

function TIntgrlTypeInfo.CreateValFromStr(str: string): pointer;
begin
  result := AllocMem(tyValSize);
  ReadValFromStr(result, str);
end;

procedure TIntgrlTypeInfo.ReadValFromStr(var data: pointer; str: string);
begin
  //
end;

function TIntgrlTypeInfo.WriteValToStr(data: pointer): string;
begin
  //
end;

procedure TIntgrlTypeInfo.CopyVal(var data: pointer; copy: pointer);
begin
  Move(copy^,data^,tyValSize);
end;

function TIntgrlTypeInfo.EquVal(data, copy: pointer): boolean;
begin
  result := CompareByte(copy^,data^,tyValSize) = 0;
end;

  { TinlConfiguration }

  //    property RootPath: string read FRootPath; // Параметры конфигурации
  //    property Plugin[plgID: TinlID]: TinlPlugin read GetPlugin;
      function InsPlugin(iiPlugin: TinlPlugin): TinlID;
      function FindPlugin(plgName: TinlNameType): TinlID;
  //    FRootPath: string;
function ActivatePlugin(plgnID: TinlID; var thePlugin: TinlPlugin): TinlLogicType;
procedure SearchPlugins;
function ProbePlugin(aPlugin: TinlLongNameType): TinlLogicType;
function GetParams: TStrings;
function GetParamString(const Name: TinlNameType): TinlStringType;
procedure SetParamString(const Name: TinlNameType; const Value: TinlStringType);
procedure RegisterPlugin(aPlugin: TPluginInfo);
procedure ErrorCfg(s: TinlStringType);
procedure WarngCfg(s: TinlStringType);
procedure HintCfg(s: TinlStringType);
procedure InfoCfg(s: TinlStringType);
property Params: TStrings read GetParams;
property ParamStr[Name: TinlNameType]: TinlStringType read GetParamString write SetParamString;

procedure TinlConfiguration.SearchPlugins;
begin
  // cfgPluginsDir
end;

function TinlConfiguration.GetParams: TStrings;
begin
  if assigned(FParams) then result := FParams else result := nil;
end;

function TinlConfiguration.GetParamString(const Name: TinlNameType
  ): TinlStringType;
begin
  result := FParams.Values[Name];
end;

procedure TinlConfiguration.SetParamString(const Name: TinlNameType;
  const Value: TinlStringType);
begin
  FParams.Values[Name] := Value;
end;

function TinlConfiguration.ProbePlugin(aPlugin: TinlLongNameType): TinlLogicType;
begin
  result := false;
end;

procedure TinlConfiguration.ErrorCfg(s: TinlStringType);
begin
  doError(cfgError+s);
end;

procedure TinlConfiguration.WarngCfg(s: TinlStringType);
begin
  doWarng(cfgWarng+s);
end;

procedure TinlConfiguration.HintCfg(s: TinlStringType);
begin
  doHint(cfgHint+s);
end;

procedure TinlConfiguration.InfoCfg(s: TinlStringType);
begin
  doInfo(cfgInfo+s);
end;

IntegralMainForm.IntgrlCfg := IIntegralConfig;
LogViewForm.iLog := SystemLog;
ParamsForm.iiIniCfgProv.FileName := IIntegralConfig.CfgFile;
ParamsForm.IntgrlCfgn.Active := True;
LibViewForm.SetRefDB(ReferenceDB);
DataViewForm.PrjDB := ProjectDB;
ExctnSystmForm.ExS := ExecutionSystem;
HistViewForm.SetHistDB(PrjDataHistory);

procedure ResetMessagesInGruop(msgGrpID: TMsgGrpID);
function NumberMessagesInGruop(msgGrpID: TMsgGrpID): TMsgGrpID;


TDB = class
  FSQLDB: TSQLite;
  FRemote: boolean;
  FMaxNames: integer;
  FConnected: boolean;
  FReaded: boolean;
  FNames: boolean;
  FTables: TStringList;
  FNameFields: TStringList;
  function GetFulSrcPath: string;
  function GetTableFields(i: integer): TStrings;
  function GetTableValNames(i: integer): TStrings;
  procedure SetConnected(Value: boolean);
  procedure ClearFields; virtual;
  function ReadNames: boolean;
  function ReadDB: boolean;
protected
  procedure ConnectDB; virtual;
  procedure CloseDB; virtual;
  procedure CreateDB; virtual;
public
  property FullSrcPath: string read GetFulSrcPath;
  property SrcName: string read FSrcName;
  property Remote: boolean read FRemote default false;
  property Connected: boolean read FConnected default false;
  property TablesName: TStringList read FTables;
  property NameFields: TStringList read FNameFields;  // Имя поля с именами объектов для каждой базы
  property TableFields[Index: integer]: TStrings read GetTableFields;
  property TableValNames[Index: integer]: TStrings read GetTableValNames;
  property MaxNames: integer read FMaxNames write FMaxNames default 1000;

end;

  constructor TinlDBDriver.Create(wCfg: TinlConfiguration; aName: TinlNameType);
  begin
    inherited Create(wCfg, pgBase, aName);
    FTables := TStringList.Create;
    FNameFields := TStringList.Create;
  //  Post('---');
  end;

  destructor TinlDBDriver.Destroy;
  begin
    if FConnected then CloseDB;
    FNameFields.Free;
    FTables.Free;
    inherited Destroy;
  end;

  function TinlDBDriver.GetFulSrcPath: string;
  begin
    result := FSrcPath + FSrcName;
  end;

  procedure TinlDBDriver.SetConnected(Value: boolean);
  begin
    if FConnected = Value then exit;
    if Value then ConnectDB else CloseDB;
  end;

  function TinlDBDriver.GetTableFields(i: integer): TStrings;
  begin
    result := nil;
    if FConnected and (i<FTables.Count) then
      if not FReaded and not ReadDB then exit
      else result := TStringList(FTables.Objects[i]);
  end;

  function TinlDBDriver.GetTableValNames(i: integer): TStrings;
  begin
    result := nil;
    if FConnected and (i<FTables.Count) then
      if not FNames and not ReadNames then exit
      else result := TStringList(TStringList(FTables.Objects[i]).Objects[0]);
  end;

  procedure TinlDBDriver.ClearFields;
  var
    i: integer;
  begin
    for i := FTables.Count-1 downto 0 do
      with FTables.Objects[i] as TStringList do begin
        Objects[0].Free;
        Free;
      end;
  end;

  procedure TinlDBDriver.ConnectDB;
  var
    i: Integer;
  begin
  //  Post(logDBopen + logDB + FSrcName);
    if FConnected then exit;
    try
      FSQLDB := TSQLite.Create(FullSrcPath);
      FConnected := true;
      FNameFields.Clear;
      FTables.Clear;
  //    Post(logDBtables);
      if FSQLDB.Query('SELECT tbl_name FROM SQLITE_MASTER WHERE type = ''table''', FTables) then begin
        if (FTables.Count=0) then begin
          goError(logDBempty);
          CloseDB;
        end else begin
          FTables.Delete(0);
  //        Post('Found ' + inttostr(FTables.Count) + ' tables');
  //        for i := 0 to FTables.Count-1 do Post(inttostr(i) + ' : ' + FTables[i]);
        end;
      end else begin
        goError('Query tables ERROR');
        CloseDB;
      end;
    finally
      FReaded := false;
      FNames := false;
    end;
  end;

  procedure TinlDBDriver.CloseDB;
  begin
  //  Post(logDBclose + logDB + FSrcName);
    if not FConnected then exit;
    try
      FSQLDB.Free;
      FConnected := false;
    finally
      if FReaded then ClearFields;
      FNameFields.Clear;
      FTables.Clear;
      FReaded := false;
      FNames := false;
    end;
  end;

  procedure TinlDBDriver.CreateDB;
  begin
    //
  end;

  function TinlDBDriver.ReadDB: boolean;
  var
    i, j: integer;
    SL: TStringList;
    s: string;
  begin
  //  Post(logDBread + logDB + FSrcName);
    if FReaded then exit;
    if not FConnected then ConnectDB;
    if FConnected and (FTables.Count>0) then begin
      for i := 0 to FTables.Count-1 do begin
        SL := TStringList.Create;
        if FSQLDB.Query('SELECT sql FROM SQLITE_MASTER WHERE type = ''table'' AND name NOT LIKE ''sqlite_%''', SL) then begin
          j := 0;
          repeat
            s := SL[j];
  //          ExtractSubstr();
  //          ExtractDelimited
            inc(j);
          until j=SL.Count;
        end;
        FTables.Objects[i] := SL;
        SL := TStringList.Create;
        if FSQLDB.Query('SELECT ' + FNameFields[i] + ' FROM ' + FTables[i], SL) then
          TStringList(FTables.Objects[i]).Objects[0] := SL;
      end;
      result := true;
    end else result := false;
  end;

  function TinlDBDriver.ReadNames: boolean;
  var
    i, j: integer;
    SL: TStringList;
  begin
  //  Post(logDBnames + logDB + FSrcName);
    if FNames then exit;
    if not FConnected then ConnectDB;
    if FConnected and (FTables.Count>0) then begin
      if not FReaded then ReadDB;
      if FReaded then begin
        for i := 0 to FTables.Count-1 do begin
          SL := TStringList.Create;
          if FSQLDB.Query('SELECT sql FROM SQLITE_MASTER WHERE type = ''table''', SL) then begin
            j := 0;
            repeat
              s := SL[j];

              inc(j);
            until j=SL.Count;
          end;
          FTables.Objects[i] := SL;
          SL := TStringList.Create;
          if FSQLDB.Query('SELECT ' + FNameFields[i] + ' FROM ' + FTables[i], SL) then begin
            TStringList(FTables.Objects[i]).Objects[0] := SL;
          end;
        end;
    end;
  end;

  procedure CreateNewDB;
  var
    SQLDB: TSQLite;
  begin
    SQLDB := TSQLite.Create(ProjectDBname);
    SQLDB.Query(newDBsql, nil);
    SQLDB.Free;
  end;

const

newDBsql = 'CREATE TABLE objects ("obID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "obName" TEXT NOT NULL, '
 + '"obType" TEXT NOT NULL DEFAULT (''OBJECT''), "obOwner" INTEGER DEFAULT (1), '
 + '"obState" TEXT NOT NULL DEFAULT (''UNDEF''), "obSource" TEXT NOT NULL DEFAULT (''INPUT''), '
 + '"obVersion" INTEGER NOT NULL DEFAULT (0), "obTime" DATETIME NOT NULL, "obDesc" TEXT);';

function b2s(b: TclcBool): TclcStrng; inline;
function i2s(i: TclcIntgr): TclcStrng; inline;
function h2s(i: TclcIntgr): TclcStrng; inline;
function r2s(r: TclcReal): TclcStrng; inline;
function c2s(c: TclcCmplx): TclcStrng; inline;
function i2b(i: TclcIntgr): TclcBool; inline;
function r2b(r: TclcReal): TclcBool; inline;
function s2b(s: TclcStrng): TclcBool; inline;
function int2idx(i: TclcIntgr): TclcIndex; inline;

  function b2s(b: TclcBool): TclcStrng;
  begin
    if b then result := sTrue else result := sFalse;
  end;

  function i2s(i: TclcIntgr): TclcStrng;
  begin
    result := IntToStr(i);
  end;

  function h2s(i: TclcIntgr): TclcStrng;
  begin
    // result := ;
  end;

  function r2s(r: TclcReal): TclcStrng;
  begin
  //  str(
    // result := ;
  end;

  function c2s(c: TclcCmplx): TclcStrng;
  begin
    // result := ;
  end;

  function i2b(i: TclcIntgr): TclcBool;
  begin
    result := i<>0;
  end;

  function r2b(r: TclcReal): TclcBool;
  begin
    result := r<>0;
  end;

  function s2b(s: TclcStrng): TclcBool;
  begin
    result := (s='1')or(s=sTrue)or(s=sOn)or(s=sYes)or(s=sEnabled);
  end;

  function int2idx(i: TclcIntgr): TclcIndex; inline;
  begin
    if i>0 then result := i;
  end;

